<?php

namespace backend\models\goods\cate;

use common\models\goods\cate\GoodsCateModel;

/**
 * Desc 分类管理模型
 */
class GoodsCate extends GoodsCateModel
{


    /**
     * @desc 递归获取树状菜单
     * @return string
     * */
    public static function arrayTree($ary = [], $route_parent_id = 0, $level = 10, $i = 1)
    {
        $arr = [];
        foreach ($ary as &$rs) {
            if ($rs['pid'] != $route_parent_id) {
                continue;
            }
            if ($i > $level) {
                break;
            }

            $arr[$rs['id']] = $rs;
            $n = $i;
            $n++;
            $children = self::arrayTree($ary, $rs['id'], $level, $n);
            if ($children) {
                $arr[$rs['id']]['children'] = $children;
            } else {
                $arr[$rs['id']]['children'] = [];
            }
        }
        if ($arr) {
            $arr = array_values($arr);
        }
        return $arr;
    }

}
